<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var assginUserDataGrid;
//var IsCheckFlag = true; //标示是否是勾选复选框选中行的，true - 是 , false - 否
    $(function() {
       /*  $('#assignUserForm').form({
            url : '${path }/department/saveAssignUser',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                 	parent.$.messager.show({title: '提示！',msg:result.msg});
                    parent.$.modalDialog.handler.dialog('close');
                } else {
                    var form = $('#assignUserForm');
                    parent.$.messager.alert('提示', eval(result.msg), 'warning');
                }
            }
        }); */
    
        assginUserDataGrid = $('#assginUserDataGrid').datagrid({
            url : '${path }/admin/department/assignUserList',
            fit : true,
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect:true,  
            checkOnSelect:true,  
            selectOncheck:true,
            idField : 'id',
            sortName : 'createTime',
	        sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20],
            columns : [ [  {
                width : '128',
                checkbox:true,
                field : 'id'
            },{
                width : '80',
                title : '登录名',
                field : 'loginName',
                sortable : true
            }, {
                width : '80',
                title : '姓名',
                field : 'name',
                sortable : true
            },{
                width : '40',
                title : '性别',
                field : 'sex',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '男';
                    case 1:
                        return '女';
                    }
                }
            },{
                width : '120',
                title : '电话',
                field : 'phone',
                sortable : true
            },{
                width : '120',
                title : '邮箱',
                field : 'email',
                sortable : true
            },{
                width : '60',
                title : '状态',
                field : 'status',
                sortable : true,
                formatter : function(value, row, index) {
                    switch (value) {
                    case 0:
                        return '正常';
                    case 1:
                        return '停用';
                    }
                }
            } 
            /* , {
                field : 'action',
                title : '操作',
                width : 130,
                formatter : function(value, row, index) {
                    var str = '';
                        <shiro:hasPermission name="/user/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="user-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editUserFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>
                        <shiro:hasPermission name="/user/delete">
                            str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="user-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="deleteUserFun(\'{0}\');" >删除</a>', row.id);
                        </shiro:hasPermission>
                    return str;
                }
            } */
            ] ],
            onLoadSuccess:function(data){
             //  $('.user-easyui-linkbutton-edit').linkbutton({text:'编辑'});
             //   $('.user-easyui-linkbutton-del').linkbutton({text:'删除'});
            },onSelect: function (rowIndex, rowData) {
		         if (!IsCheckFlag) {
		             IsCheckFlag = true;
		             $("#assginUserDataGrid").datagrid("unselectRow", rowIndex);
		         }
		     },                    
		     onUnselect: function (rowIndex, rowData) {
		         if (!IsCheckFlag) {
		             IsCheckFlag = true;
		             $("#assginUserDataGrid").datagrid("selectRow", rowIndex);
		         }
		      }
        });
    });
    
 function saveAssignUserFun() {
 	var depid=parent.getDepartmentId();
 	$("#departmentIds").val(depid);
 	 var ids = null;
      var f = $('#assginUserDataGrid');
      var rows = f.datagrid('getSelections');
	if (rows.length==0){ 
		$.messager.alert({title: '提示',msg: '请选择信息！'});
	    return ;
	}
	for(var i=0;i<rows.length;i++){
		ids=rows[i].id;
	}
	$("#userId").val(ids);
    $('#assignUserForm').form('submit', {
        url : '${path }/admin/department/saveAssignUser',
        /*  onSubmit: function() {
         	progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
        }, */
        success: function(result) {
         	progressClose();
            result = $.parseJSON(result);
            if (result.success) {
             	parent.$.modalDialog.handler.dialog('close');
                parent.$.messager.show({title: '提示！',msg:result.msg});
             }else {
                parent.$.messager.show({title: '提示！',msg:result.msg});
            }
        }
    });
}   
    function searchUserFun() {
        assginUserDataGrid.datagrid('load', $.serializeObject($('#searchUserForm')));
    }
    function cleanUserFun() {
        $('#searchUserForm input').val('');
        assginUserDataGrid.datagrid('load', {});
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="searchUserForm">
            <table>
                <tr>
                    <th>姓名:</th>
                    <td><input name="name" placeholder="请输入用户姓名"/></td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchUserFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanUserFun();">清空</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="saveAssignUserFun();">确定</a> 
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div data-options="region:'center',border:true,title:'用户列表'" >
        <table id="assginUserDataGrid" data-options="fit:true,border:false"></table>
    </div>
    <div style="display: none;">
    	<form id="assignUserForm" method="post">
    		<input type="text" name="departmentIds" id="departmentIds" value=""/>
    		<input type="text" name="userId" id="userId" value=""/>
    		<input type="text" name="type" id="type" value="1"/>
        </form>
	</div>
</div>
